package com.yanfan.accessControl.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import com.yanfan.system.util.DeptTypeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.accessControl.domain.IbmsAccessControlDevice;
import com.yanfan.accessControl.service.IIbmsAccessControlDeviceService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 门禁系统设备Controller
 *
 * @author genluo
 * @date 2024-09-20
 */
@Api(tags = "门禁系统设备")
@RestController
@RequestMapping("/accessControl/device")
public class IbmsAccessControlDeviceController extends BaseController {
    @Autowired
    private IIbmsAccessControlDeviceService ibmsAccessControlDeviceService;

    @Autowired
    private DeptTypeUtils deptTypeUtils;

    /**
     * 查询门禁系统设备列表
     */
    @ApiOperation("门禁系统设备分页列表")
    @PreAuthorize("@ss.hasPermi('accessControl:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsAccessControlDevice ibmsAccessControlDevice) {
        startPage();
        List<IbmsAccessControlDevice> list = ibmsAccessControlDeviceService.queryPageList(ibmsAccessControlDevice);
        return getDataTable(list);
    }

    /**
     * 导出门禁系统设备列表
     */
    @ApiOperation("导出门禁系统设备列表")
    @PreAuthorize("@ss.hasPermi('accessControl:device:export')")
    @Log(title = "门禁系统设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsAccessControlDevice ibmsAccessControlDevice) {
        List<IbmsAccessControlDevice> list = ibmsAccessControlDeviceService.queryPageList(ibmsAccessControlDevice);
        ExcelUtil<IbmsAccessControlDevice> util = new ExcelUtil<IbmsAccessControlDevice>(IbmsAccessControlDevice.class);
        util.exportExcel(response, list, "门禁系统设备数据");
    }

    /**
     * 获取门禁系统设备详细信息
     */
    @ApiOperation("获取门禁系统设备详细信息")
    @PreAuthorize("@ss.hasPermi('accessControl:device:query')")
    @GetMapping(value = "/{deviceSysId}")
    public AjaxResult getInfo(@PathVariable("deviceSysId") Long deviceSysId) {
        return success(ibmsAccessControlDeviceService.getById(deviceSysId));
    }

    /**
     * 新增门禁系统设备
     */
    @ApiOperation("新增门禁系统设备")
    @PreAuthorize("@ss.hasPermi('accessControl:device:add')")
    @Log(title = "门禁系统设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsAccessControlDevice ibmsAccessControlDevice) {
        ibmsAccessControlDevice.setCreateTime(DateUtils.getNowDate());
        return toAjax(ibmsAccessControlDeviceService.save(ibmsAccessControlDevice));
    }

    /**
     * 修改门禁系统设备
     */
    @ApiOperation("修改门禁系统设备")
    @PreAuthorize("@ss.hasPermi('accessControl:device:edit')")
    @Log(title = "门禁系统设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsAccessControlDevice ibmsAccessControlDevice) {
        ibmsAccessControlDevice.setUpdateTime(DateUtils.getNowDate());
        return toAjax(ibmsAccessControlDeviceService.updateById(ibmsAccessControlDevice));
    }

    /**
     * 删除门禁系统设备
     */
    @ApiOperation("删除门禁系统设备")
    @PreAuthorize("@ss.hasPermi('accessControl:device:remove')")
    @Log(title = "门禁系统设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deviceSysIds}")
    public AjaxResult remove(@PathVariable Long[] deviceSysIds) {
        return toAjax(ibmsAccessControlDeviceService.removeBatchByIds(Arrays.asList(deviceSysIds)));
    }
}
